package org.ysu.shoeShopping.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.ysu.shoeShopping.dao.ShoesizesDao;
import org.ysu.shoeShopping.entity.Shoesizes;
import org.ysu.shoeShopping.service.ShoesizesService;

import javax.annotation.Resource;
import java.util.List;

/**
 * 尺寸表(Shoesizes)表服务实现类
 *
 * @author makejava
 * @since 2025-09-13 16:59:45
 */
@Service("shoesizesService")
public class ShoesizesServiceImpl implements ShoesizesService
{
    @Resource
    private ShoesizesDao shoesizesDao;

    /**
     * 通过ID查询单条数据
     *
     * @param ssid 主键
     * @return 实例对象
     */
    @Override
    public Shoesizes queryById(Integer ssid) {
        return this.shoesizesDao.queryById(ssid);
    }

    /**
     * 分页查询
     *
     * @param shoesizes 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<Shoesizes> queryByPage(Shoesizes shoesizes, PageRequest pageRequest) {
        long total = this.shoesizesDao.count(shoesizes);
        return new PageImpl<>(this.shoesizesDao.queryAllByLimit(shoesizes, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param shoesizes 实例对象
     * @return 实例对象
     */
    @Override
    public Shoesizes insert(Shoesizes shoesizes) {
        this.shoesizesDao.insert(shoesizes);
        return shoesizes;
    }

    /**
     * 修改数据
     *
     * @param shoesizes 实例对象
     * @return 实例对象
     */
    @Override
    public Shoesizes update(Shoesizes shoesizes) {
        this.shoesizesDao.update(shoesizes);
        return this.queryById(shoesizes.getSsid());
    }

    /**
     * 通过主键删除数据
     *
     * @param ssid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer ssid) {
        return this.shoesizesDao.deleteById(ssid) > 0;
    }

    @Override
    public List<Shoesizes> findByShoeId(Integer shoeId) {
        return this.shoesizesDao.findByShoeId(shoeId);
    }
}
